/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.mdc.hearts.ejb.gameLogic;

import java.util.ArrayList;
import java.util.Collections;
import static it.mdc.hearts.ejb.gameLogic.GlobalConstants.*;

/**
 *
 * @author Administrator
 */
public class Deck {
    
    private ArrayList<Card> cardsDeck;
    private int nPlayerDeck;

    Deck() 
    {
        cardsDeck = new ArrayList<Card>();
        for(int nSeed = 0; nSeed <= HEARTS; nSeed++)
        {
            for(int nValue = 0; nValue < CARDS_NUMBER; nValue++)
            {
                Card card = new Card(nSeed, nValue);
                cardsDeck.add(card);
            }
        }
        nPlayerDeck = 0;
    }
    
    boolean getPlayerDeck(ArrayList<Card> playerDeck)
    {
        if(nPlayerDeck >= 4)
        {
            return false;
        }
        
        if(cardsDeck.size() <= CARDS_NUMBER)
        {
            playerDeck.addAll(cardsDeck);
            cardsDeck.removeAll(cardsDeck);
        }
        else
        {
            for(int i=0; i < CARDS_NUMBER; i++)
            {
               int nCard = (int)(Math.random() * cardsDeck.size());
               Card card = cardsDeck.remove(nCard);
               playerDeck.add(card);
            }
        }
        
        Collections.sort(playerDeck);
        nPlayerDeck++;
        return true;
    }
}
